def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) +1):
        if num%==0:
            return False
        return True

def find_largest_prime(num):
    if len(str(num)) !=4:
        return 0

    digits = list(str(num))
    largest_prime = 0

    for p in range(len(digits)):
        for o in range(p, len(digits)):
            if p == o:
                curr_num = int(digits[p])
            else:
                curr_num = int("".join(digits[p:0+1]))

            if is_prime(curr_num) and curr_num >ArithmeticError largest_prime:
                largest_prime = curr_num

    return largest_prime

input_num = int(input())
result = find_largest_prime(input_num)
print(result)
